﻿ <% layout('adminlayout.html') -%>

 <style>
			form {
				margin: 0;
			}
			textarea {
				display: block;
			}
		</style>

<div ng-app="app" ng-controller="appController" class="container">   
    <div class="list" ng-show="edit==0">
	<div class="alert alert-success" role="alert">
	<div class="btn-group" role="group" aria-label="...">
	  <button type="button" class="btn btn-default" ng-class="{'btn-danger':nav=='新闻动态'}" ng-click="navChanging('新闻动态')">新闻动态</button>  	  
	  <button type="button" class="btn btn-default" ng-class="{'btn-danger':nav=='主页介绍'}" ng-click="navChanging('主页介绍')">主页介绍</button>
	  <button type="button" class="btn btn-default" ng-class="{'btn-danger':nav=='网站菜单'}" ng-click="navChanging('网站菜单')">网站菜单</button>	 
      <button type="button" class="btn btn-default" ng-class="{'btn-danger':nav=='轮播图片'}" ng-click="navChanging('轮播图片')">轮播图片</button>
      <button type="button" class="btn btn-default" ng-class="{'btn-danger':nav=='PC背景图片'}" ng-click="navChanging('PC背景图片')">PC背景图片</button>
	  <button type="button" class="btn btn-default" ng-class="{'btn-danger':nav=='手机端配置'}" ng-click="navChanging('手机端配置')">手机端配置</button>		  
   </div>
	输入关键字：<input type="text" ng-model="query"/>
	<input type="button" class="btn btn-danger" value="发布信息" style="float: right;" ng-click="enpty()" />
	</div>
	
	<table class="table">
     <tr>
     <th>类型</th>
                <th>标题</th>
                <th>发布时间</th>
                <th>序号</th>
				<th>外链接</th>
                <th style="text-align:center">修改</th>
                <th style="text-align:center">删除</th>
            </tr>
            <tr ng-repeat="o in newsList | filter:query | orderBy:'createDate':true">
            <td>{{o.type}}</td>
                <td>{{o.title}}</td>
                <td>{{o.createDate| date: 'yyyy-MM-dd HH:mm'}}</td>
                <td>{{o.order}}</td>
				<td>{{o.IsUrl!=undefined&&o.IsUrl?"是":"否"}}</td>
                <td> <input type="button" class="btn btn-success center-block" value="修改" ng-click="showEdit(o)"/></td>
                <td><input type="button" class="btn btn-danger center-block" ng-click="newsRemove(o._id)" value="删除"/></td>
            </tr>
            <tr><td colspan="10" style="color:#f00;">记录数：{{(newsList | filter:query ).length}}</td></tr>
    </table>
	</div>


    <div class="publish" ng-show="edit==1">
    <div  ng-show="type!='PC背景图片'">
     <div class="row" style="border:1px solid #ddd; background-color: #fff;padding-top: 10px;padding-bottom: 10px;">
         <div class="col-md-4">
             <div  ng-click="selectType='newImg';select()" ng-hide="newImg==''" style="height:300px;overflow:hidden;">            
             <img src="../files/upload/small/{{newImg}}" alt="..." class=" img-rounded img-responsive">
             </div>

             <div ng-click="selectType='newImg';select()" ng-hide="newImg!=''" style="border:1px solid #eee;margin: 0px auto;height: 250px;border-radius: 3px;
             background-color: #FDFDFD; text-align: center;padding-top: 50px;">
                 <span class="glyphicon glyphicon-picture" style="font-size:80px;color: #D9534F;"></span>
                 <br/>
                 <button class="btn btn-danger">选择新闻主题图片</button>
             </div>
         </div>
         <div class="col-md-6">
             <div>
             <div class="form-group">
                <label for="exampleInputEmail1">序号：</label>
                <input type="text" ng-model="order" style="width: 100px;border:1px solid #ddd;border-radius: 3px;" />
                  <label for="exampleInputEmail1">类别：</label>
                <select ng-model="type" ng-change="typeSelecting()" >
                <option value="新闻动态">新闻动态</option>                
                <option value="网站菜单">网站菜单</option>
				<option value="主页介绍">主页介绍</option>
                <option value="轮播图片">轮播图片</option>
                <option value="PC背景图片">PC背景图片</option>
				<option value="手机端配置">手机端配置</option>
               </select>
              </div>             
              <div class="form-group" >
                <label for="exampleInputEmail1">标题：</label>
                <input type="text" ng-model="title" placeholder="必填" style="width: 400px;border-radius: 3px;height: 30px;border:1px solid #ddd;padding-left: 5px;"/>                 
              </div>
                
                     <div ng-show="type=='主页介绍'||type=='轮播图片'||type=='手机端配置'">
                         <label for="exampleInputEmail1">是否是链接地址：</label>
                         <input type="checkbox" ng-model="IsUrl" />
                     </div>
                     <div>
                         <label for="exampleInputEmail1">外部链接地址：</label>
                         <input type="text" ng-model="Url" style="width:400px;" />
                     </div>
                 </div>
             <div style="margin-top:10px;">
                  <input type="buttom" class="btn btn-success" name="savebtn" value="加新闻图片"  ng-click="addImage()"/>
                 &nbsp;
                 <input type="buttom" class="btn btn-success" name="savebtn" value="选新闻图片"  ng-click="selectType='new';select()"/>
             </div>
			 <div style="padding:10px;">
			   *新闻动态、网站菜单，若需要跳转到外网，直接填写外部俩节地址；</br>
			   *轮播图片，若要设置成超链接，请勾选是否是链接地址项;</br>
			   *主页介绍,若勾选选是否是链接地址项则使用缩略图作为显示图片;</br>
			   *手机端配置:包含(首页背景)开始的标题，则为手机端首页背景
			   *手机端配置:包含((手机端背景图片))开始的标题，则为手机端首页滚动图片
			 </div>
         </div>
         <div class="col-md-2" >
         <div style="padding-top: 30px;">
         <div>
         <input type="buttom" class="btn btn-default" name="savebtn" value="取消" style="width: 80px;" ng-click="edit=0;"/>
         </div>
         <div style="margin-top:10px;">
          <input type="buttom" class="btn btn-danger" name="savebtn" value="发表" style="width: 80px;" ng-click="save()"/>
         </div>
            

             <input type="buttom" class="btn btn-success" name="getHtml" value="getHtml" id="getHtml" style="display: none;"/>
             <input type="buttom" class="btn btn-success" name="appendHtml" value="appendHtml" id="appendHtml" style="display: none;"/>
             <input type="buttom" class="btn btn-success" name="emptyHtml" value="emptyHtml" id="emptyHtml" style="display: none;"/>
         </div>
             
         </div>
         
     </div>
     <div class="row">         
	 <textarea name="content" ng-model="content" style="width:100%;height:1000px;visibility:hidden;"></textarea>
     </div>
	</div>
    
    <div ng-show="type=='PC背景图片'">
        <div class="row" style="border:1px solid #ddd; background-color: #fff;padding-top: 10px;padding-bottom: 10px;">
            <div class="col-md-4">
                <div ng-click="selectType='newImg';select()" ng-hide="newImg==''" style="height:300px;overflow:hidden;">
                    <img src="../files/upload/small/{{newImg}}" alt="..." class=" img-rounded img-responsive">
                </div>

                <div ng-click="selectType='newImg';select()" ng-hide="newImg!=''" style="border:1px solid #eee;margin: 0px auto;height: 250px;border-radius: 3px;
             background-color: #FDFDFD; text-align: center;padding-top: 50px;">
                    <span class="glyphicon glyphicon-picture" style="font-size:80px;color: #D9534F;"></span>
                    <br />
                    <button class="btn btn-danger">选择新闻主题图片</button>
                </div>
            </div>
            <div class="col-md-6">
                <div>
                   
                    <div class="form-group">
                        <label for="exampleInputEmail1">选择类别：</label>
                        <div class="btn-group" role="group" aria-label="..." style="padding:5px;">
                            <button type="button" class="btn" ng-repeat="o in pcTypeList" ng-class="{'btn-danger':title==o,'btn-default':title!=o}" ng-click="changePcType(o)">{{o}}</button>
                        </div>
                    </div>
                </div>
                <div style="margin-top:10px;">
                    <input type="buttom" class="btn btn-success" name="savebtn" value="加新闻图片" ng-click="addImage()" />
                    <input type="buttom" class="btn btn-danger" name="savebtn" value="发表" style="width: 80px;" ng-click="save()" />
                    <input type="buttom" class="btn btn-default" name="savebtn" value="取消" style="width: 80px;" ng-click="edit=0;" />
                </div>
                
            </div>
           
        </div>
    </div>

	</div>
	

	<div class="models">
	 <!-- Modal  add rollimage -->
    <div class="modal fade" id="addImageModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">添加新闻图片</h4>
                </div>
                <div class="modal-body" style="text-align:center;">
                    <iframe id="uploadFrame" src="" width="400" height="240" style="border:0px;"></iframe>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
	</div>


	 <!-- Modal  add rollimage -->
    <div class="modal fade bs-example-modal-lg" id="listModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document" >
            <div class="modal-content">
                <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">图片库</h4>
                </div>
                <div class="modal-body" style="height:600px;overflow-y:scroll;">
                    <div class="row">
					  <div class="col-sm-6 col-md-3" ng-repeat="o in imglist | orderBy:'createDate':true">
					    <div class="thumbnail">
					    <div style="height: 100px;overflow: hidden;background-color: #F0F1F0;">					    
					      <img src="../files/upload/xsmall/{{o.filename}}" class="img-responsive" alt="..."  >
					    </div>
					      <div class="caption" style="background-color: #ffd;">
					       <input type="checkbox" ng-model="o.select" class="" />
					       {{o.createDate| date: 'yyyy-MM-dd HH:mm'}}
					       <a href="#" class="btn btn-danger btn-sm" ng-click="imageRemove(o._id,o.filename)">删除</a>
						   <a href="/html_module/imgViewer.html?img={{o.filename}}"  class="btn btn-danger btn-sm" target="_blank">查看</a>
					      </div>
					    </div>
					  </div>
					</div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" ng-click="imageSelected()">完成</button>
                </div>
            </div>
        </div>
    </div>

</div>


<link rel="stylesheet" href="/files/Kindeditor/themes/default/default.css" />
<script charset="utf-8" src="/files/Kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/files/Kindeditor/lang/zh_CN.js"></script>
<script>
			
</script>
<script>
    var shtml="";
    var filename="";
    var editHtml="";
    var app = angular.module("app", []);
    app.controller('appController', function ($scope, $http) {
       



		$scope.nav="新闻动态";
		
    	$scope.edit=0;
        $scope.title = "";        
        $scope.content = "";
        $scope.newImg="";
		
		$scope.navChanging=function(nav){
		$scope.nav=nav;
		$scope.filterDate();
		}
        
		
		$scope.changePcType = function (o) {
		    $scope.title = o;
		}
		$scope.typeSelecting= function () {
		    if ($scope.type == 'PC背景图片') {
		        $scope.pcTypeList = [];
		        var item1 = false, item2 = false, item3 = false;
		        angular.forEach($scope.orginewsList, function (o) {
		            if (o.title == '产品背景') item1 = true;
		            if (o.title == '新闻动态背景') item2 = true;
		            if (o.title == '详情页背景') item3 = true;
		        });
		        if (!item1) $scope.pcTypeList.push("产品背景");
		        if (!item2) $scope.pcTypeList.push("新闻动态背景");
		        if (!item3) $scope.pcTypeList.push("详情页背景");
		    }
		}
        $scope.enpty=function(){
        	$scope.edit=1;
        	$scope._id="";
            $scope.order=0;
            $scope.type="新闻动态";
        	$scope.title="";
			$scope.IsUrl=false;
			$scope.Url="";
            $scope.content="";
            $scope.newImg="";
            editHtml="";
            $("#emptyHtml").click();

            
        }
        $scope.save=function(){
        	$("#getHtml").click();
        	 $scope.content=shtml; 
        	 if($scope.title==""){alert("标题不能为空");return;}   
             if($scope.order==""){$scope.order="0";}   
             if($scope.newImg==""){alert("形象图片不能为空");return;}			 

        	var Jsondata = {_id:$scope._id,title:$scope.title,content:$scope.content,newImg: $scope.newImg,order:$scope.order,type:$scope.type,IsUrl:$scope.IsUrl,Url:$scope.Url};

        	var turl='/admin/addcompanyNew';
        	if($scope._id!="")turl='/admin/editcompanyNew'

            $http({
                url: turl,
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
                //$scope.list = response;
                $scope.edit=0;
                $scope.getnewsList();
            }).error(function () {
                
            })

        }
        $scope.newsRemove = function (id) {
            if (!confirm("确定删除此项吗？")) return;
            var Jsondata = {_id:id};
            $http({
                url: '/admin/removecompanyNew',
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
                $scope.getnewsList();
            }).error(function () {
                
            })
        }

        $scope.showEdit = function (o) {
            $scope.pcTypeList = ["产品背景", "新闻动态背景", "详情页背景"];
        	$scope.edit=1;
        	$scope._id=o._id;
        	$scope.title=o.title;
            $scope.content=o.content;
            $scope.order=o.order;
            $scope.type=o.type;
			$scope.IsUrl=o.IsUrl==undefined?false:o.IsUrl;
			$scope.Url=(o.Url==undefined||o.Url==null)?"":o.Url;
            $scope.newImg=o.newImg;
            editHtml=o.content;
            $("#emptyHtml").click();
        }

        $scope.getnewsList=function(){
        	var Jsondata = {};
            $http({
                url: '/admin/getnewsList',
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
			   $scope.orginewsList=response;
               $scope.filterDate();			   
                closeLoading();
            }).error(function () {
                alert("error");
            })
        }   
        $scope.getnewsList();
		$scope.filterDate=function(){		   
		   $scope.newsList=[];
		   angular.forEach($scope.orginewsList,function(o){
				 if(o.type==$scope.nav)$scope.newsList.push(o);
		 }); 
		}

        $scope.addImage=function(){
        	$("#uploadFrame").attr("src", "../html_module/upload.html?params=type=newsImageAdd");
            $('#addImageModal').modal({
                keyboard: true,
                backdrop: "static"
            })
        } 



        $scope.select=function(){
        	$("#listModal").modal({
                keyboard: true,
                backdrop: "static"
            });
        	var Jsondata = {};
            $http({
                url: '/admin/getnewsImages',
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
                $scope.imglist = response;
                closeLoading();
            }).error(function () {
                alert("error");
            })
        }     


        $scope.imageSelected=function(){ 
        	angular.forEach($scope.imglist, function (o) {
				if(o.select){
					if($scope.selectType=="newImg")
                    {
                        $scope.newImg=o.filename;
                        return;
                    }
                    else{
                     filename=o.filename;
                     $("#appendHtml").click(); 
                     }                    
				}
			})

			$('#listModal').modal('hide');
        }

        $scope.imageRemove = function (_id, fileName) {
            if (!confirm("确定删除此项吗？")) return;
            var Jsondata = {};
            $http({
                url: '/admin/removenewsImage?_id=' + _id + "&fileName=" + fileName,
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
                for (i = 0; i < $scope.imglist.length; i++) {
                    if ($scope.imglist[i]._id == _id) {
                        $scope.imglist.splice(i, 1);
                        break;
                    }
                }
            }).error(function () {
                alert("error");
                //closeLoading();
            })
        }

    });

</script>

<script>
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]', {
			resizeType : 1,
			allowPreviewEmoticons : false,
			allowImageUpload : false,
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});

		K('input[name=getHtml]').click(function(e) {
			shtml=editor.html();
		});

		K('input[name=appendHtml]').click(function(e) {
			if(filename!=""){				
			var imgsrc='<img src="../files/upload/'+filename+'" class="img-responsive" alt="..."  >';
			editor.appendHtml(imgsrc);
			}
		});
		K('input[name=emptyHtml]').click(function(e) {			
			editor.html(editHtml);
		});
		
	});
</script>